package com.zcx.qshop.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.R;

/**
 * Created by Administrator on 2015/8/24 0024.
 */
public class SearchBarView extends LinearLayout implements View.OnClickListener{

    @BoundView(R.id.search_bar_hot) private ViewGroup hot;

    @BoundView(R.id.search_bar_after) private ViewGroup after;

    public OnItemClickListener onItemClickListener;

    public SearchBarView(Context context, AttributeSet attrs) {

        super(context, attrs);

        BoundViewHelper.boundView(this, LayoutInflater.from(context).inflate(R.layout.view_search_bar, this));

        hot.setOnClickListener(this);

        after.setOnClickListener(this);

    }

    public void setSelect(ViewGroup viewGroup, boolean isSelect){

        ((TextView) viewGroup.getChildAt(0)).setTextColor(getResources().getColor(isSelect ? R.color.dominant_tone_one : R.color.dominant_tone_two));

        viewGroup.getChildAt(1).setVisibility(isSelect ? View.VISIBLE : View.INVISIBLE);

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){

        this.onItemClickListener = onItemClickListener;

        onClick(hot);

    }

    @Override
    public void onClick(View v) {

        setSelect(hot, false);

        setSelect(after, false);

        setSelect((ViewGroup) v, true);

        switch (v.getId()){

            case R.id.search_bar_hot:

                onItemClickListener.onHotClick();

                break;

            case R.id.search_bar_after:

                onItemClickListener.onAfterClick();

                break;

        }

    }

    public interface OnItemClickListener{

        void onHotClick();

        void onAfterClick();

    }

}
